package ten_MergeTwoSortedLists;

public class CSolution {

    public static void main(String[] args) {
        System.out.println("aa");
    }

    private static ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        if (l1 == null) {
            return l2;
        }
        if (l2 == null) {
            return l1;
        }
        ListNode head = null;
        if (l1.val <= l2.val) {
            head = l1;
            l1 = l1.next;
        } else {
            head = l2;
            l2 = l2.next;
        }
        ListNode nextNode = head;
        while (l1 != null || l2 != null) {
            if (l1 == null) {
                nextNode.next = l2;
                break;
            } else if (l2 == null) {
                nextNode.next = l1;
                break;
            } else if (l1.val <= l2.val) {
                nextNode.next = l1;
                nextNode = nextNode.next;
                l1 = l1.next;
            } else if (l1.val > l2.val) {
                nextNode.next = l2;
                nextNode = nextNode.next;
                l2 = l2.next;
            }
        }
        return head;
    }
}
